package com.ytjj.qmyx.mall.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.common.utils.feishu.FeiShuUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
@RequestMapping("/webhook")
@Slf4j
public class WebhookController {

    /**
     * 前端飞书报警
     * @param msg
     * @return
     */
    @PostMapping("/sendFeishu")
    public CommonResult sendFeishu(@RequestBody String msg) {
        FeiShuUtil.sendMsg(msg);
        return CommonResult.success();
    }

    /**
     * 记录前端日志
     * @param msg
     * @return
     */
    @PostMapping("/sendLog")
    public CommonResult sendLog(@RequestBody String msg) {
        log.info("前端日志:{}",msg);
        if(!msg.contains(":cancel") && !msg.contains("system:access_denied")){
            FeiShuUtil.sendMsg(String.format("注意注意！用户无法支付！！ ==>%s",msg) );
        }
        return CommonResult.success();
    }
}
